package com.kirayous.admin.controller;


import com.kirayous.api.admin.service.IResourceService;
import com.kirayous.api.admin.service.IRoleService;
import com.kirayous.common.Result;
import com.kirayous.common.vo.ConditionVO;
import com.kirayous.common.vo.ResourceVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author KiraYous
 * @since 2021-09-26
 */
@RestController
public class ResourceController {



    @Autowired
    IResourceService resourceService;

    /**
     * 查看角色资源选项
     *
     * @return 角色资源选项
     */
    @ApiOperation(value = "查看角色资源选项")
    @GetMapping("/admin/role/resources")
    public Result listResourceOption() {
        return Result.success().setData(resourceService.listResourceOption());
    }
    /**
     * 查看资源列表
     *
     * @return  资源列表
     */
    @ApiOperation(value = "查看资源列表")
    @GetMapping("/admin/resources")
    public Result listResources(ConditionVO conditionVO) {
        return Result.success(resourceService.listResources(conditionVO));
    }


    /**
     * 新增或修改资源
     *
     * @param resourceVO 资源信息
     * @return
     */
    @ApiOperation(value = "新增或修改资源")
    @PostMapping("/admin/resources")
    public Result saveOrUpdateResource(@RequestBody @Valid ResourceVO resourceVO) {
        resourceService.saveOrUpdateResource(resourceVO);
        return Result.success();
    }


    /**
     * 删除资源
     *
     * @param resourceId 资源id
     * @return
     */
    @ApiOperation(value = "删除资源")
    @DeleteMapping("/admin/resources/{resourceId}")
    public Result deleteResource(@PathVariable("resourceId") Integer resourceId) {
        resourceService.deleteResource(resourceId);
        return Result.success();
    }

}

